﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SerialHelper
{
   
    public partial class Main : Form
    {
        // 假设这是你的List数组
        List<DataItem> dataList = new List<DataItem>
        {
            new DataItem { Name = "Item1", Value = "Value1",Age="25" },
            new DataItem { Name = "Item2", Value = "Value2",Age="26" } 
            // ... 其他数据项
        };
        public Main()
        {
            InitializeComponent();

            // 创建一个DataTable
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("ID", typeof(int));
            dataTable.Columns.Add("Name", typeof(string));
            dataTable.Rows.Add(1, "Alice");
            dataTable.Rows.Add(2, "Bob");

            // 创建一个ComboBox列
            DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
            comboBoxColumn.HeaderText = "Choose Name";
            comboBoxColumn.Name = "ComboBoxColumn";
            comboBoxColumn.DataSource = dataTable; // 使用DataTable作为下拉框的数据源
            comboBoxColumn.DisplayMember = "Name"; // 显示在下拉框中的字段
            comboBoxColumn.ValueMember = "ID"; // 对应的值
            dataGridView.Columns.Add(comboBoxColumn);

            // 设置DataGridView的数据源
            dataGridView.DataSource = dataTable;
        }

        private void Main_Load(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.Show();
        }
    }

    // 假设这是你的数据模型类
    public class DataItem
    {
        public string Name { get; set; }
        public object Value { get; set; }
        public object Age { get; set; }
    }
}
